﻿Imports System.IO.IsolatedStorage
Imports System.Windows.Forms
Imports Runa.Scripting

Public Class FormGameChooser
    Public Property GameName() As String

    Private Sub FormGameChooser_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim gameList = fileStorage.GetFileNames("*.zip")
        For Each game In gameList
            Try
                Dim gParser As New GameParser(game, fileStorage)
                g_gameList.Add(gParser)
                Me.LB_GameList.Items.Add(gParser.Name)
            Catch ex As Exception
                Continue For
            End Try
        Next
        Me.GameName = g_gameList(0).Name
    End Sub

    Private Sub FormGameChooser_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        For i As Double = 1 To 0 Step -0.1
            Me.Opacity = i
            Threading.Thread.Sleep(100)
        Next
    End Sub

    Private Sub Btn_About_Click(sender As System.Object, e As System.EventArgs) Handles Btn_About.Click
        Using frmAbout As New AboutBox
            frmAbout.ShowDialog()
        End Using
    End Sub

    Private Sub Btn_Exit_Click(sender As System.Object, e As System.EventArgs) Handles Btn_Exit.Click
        End
    End Sub

    Private Sub Btn_Load_Click(sender As System.Object, e As System.EventArgs) Handles Btn_Load.Click
        If Me.LB_GameList.SelectedItems.Count > 0 Then
            Me.GameName = Me.LB_GameList.SelectedItem.ToString()
            Me.Hide()
            Dim thr As New Threading.Thread(
                Sub(gn)
                    Using game As New GameRenderForWindows(gn.ToString())
                        game.Run()
                    End Using
                    End
                End Sub)
            thr.Start(GameName)
        Else
            MessageBox.Show("Please choose a game to play!")
        End If
    End Sub

End Class